import java.util.ArrayList;

public class Solution38 {
    public String countAndSay(int n) {
        if (n==1){
            return "1";
        }
        ArrayList<Character> arrayList=new ArrayList<>();
        arrayList.add('1');
        for (int i=2;i<=n;i++){
            ArrayList<Character> characters=new ArrayList<>();
            char last=arrayList.get(0);
            int num=0;
            for (Character character : arrayList) {
                if (character==last){
                    num++;
                }else {
                    while (num!=0){
                        int t=num%10;
                        characters.add((char) (t+'0'));
                        num=num/10;
                    }
                    characters.add(last);
                    last=character;
                    num=1;
                }
            }
            while (num!=0){
                int t=num%10;
                characters.add((char) (t+'0'));
                num=num/10;
            }
            characters.add(last);
            arrayList=characters;
        }
        StringBuilder stringBuilder=new StringBuilder();
        for (Character character : arrayList) {
            stringBuilder.append(character);
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println(new Solution38().countAndSay(4));
    }
}
